home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cpptutor.arc / SCHEDULE.CPP < prev    next >
C/C++ Source or Header  |  1991-04-28  |  8KB  |  259 lines

  1. #include "iostream.h"
  2. #include "stdio.h"
  3. #include "conio.h"
  4. #include "schedule.hpp"
  5. #include "items.hpp"
  6. #include "location.hpp"
  7. #include "clock.hpp"
  8.  
  9. extern location rest_room;
  10. extern location waiting_area;
  11. extern location gate1;
  12. extern location gate2;
  13. extern location gate3;
  14. extern location gate4;
  15. extern location plane1;
  16. extern location plane2;
  17. extern location plane3;
  18. extern location plane4;
  19. extern items personal_items;
  20. extern clock time_of_day;
  21. extern word verb;
  22.  
  23. int visited_rest_room = FALSE;   // TRUE if the rest room was visited
  24.                                  //  as checked in shuffle_gates
  25.  
  26. schedule::schedule(void)
  27. {
  28.    flight_number[0] = 222;
  29.    flight_number[1] = 17;
  30.    flight_number[2] = 141;
  31.    flight_number[3] = 79;
  32.    destination[0] = "HAWAII";
  33.    destination[1] = "PARIS ";
  34.    destination[2] = "ROME  ";
  35.    destination[3] = "TAHITI";
  36.    depart_hour[0] = 9;
  37.    depart_hour[1] = 9;
  38.    depart_hour[2] = 9;
  39.    depart_hour[3] = 9;
  40.    depart_minute[0] = 19;
  41.    depart_minute[1] = 17;
  42.    depart_minute[2] = 16;
  43.    depart_minute[3] = 18;
  44.    gate[0] = &gate1;
  45.    gate[1] = &gate2;
  46.    gate[2] = &gate3;
  47.    gate[3] = &gate4;
  48.    flights_frozen = FALSE;
  49.    gates_frozen = FALSE;
  50.    my_gate = 0;
  51. }
  52.  
  53.  
  54.  
  55.  
  56. void
  57. schedule::shuffle_flights(void)
  58. {
  59.    if (!flights_frozen)             // Until flights are frozen,
  60.       my_gate = (my_gate + 1) % 4;  //  select the next flight
  61.                                     //  at the next gate.
  62. }
  63.  
  64.  
  65.  
  66.  
  67. void
  68. schedule::shuffle_gates(location *current_location)
  69. {
  70. int temp;
  71. char *temp_point;
  72.  
  73.    if (current_location == &rest_room)
  74.       visited_rest_room = TRUE;
  75.  
  76.    if ((current_location == gate[my_gate]) && (!gates_frozen)) {
  77.  
  78.       temp             = flight_number[0];
  79.       flight_number[0] = flight_number[1];
  80.       flight_number[1] = flight_number[2];
  81.       flight_number[2] = flight_number[3];
  82.       flight_number[3] = temp;
  83.  
  84.       temp_point     = destination[0];
  85.       destination[0] = destination[1];
  86.       destination[1] = destination[2];
  87.       destination[2] = destination[3];
  88.       destination[3] = temp_point;
  89.  
  90.       temp           = depart_hour[0];
  91.       depart_hour[0] = depart_hour[1];
  92.       depart_hour[1] = depart_hour[2];
  93.       depart_hour[2] = depart_hour[3];
  94.       depart_hour[3] = temp;
  95.  
  96.       temp             = depart_minute[0];
  97.       depart_minute[0] = depart_minute[1];
  98.       depart_minute[1] = depart_minute[2];
  99.       depart_minute[2] = depart_minute[3];
  100.       depart_minute[3] = temp;
  101.  
  102.       my_gate = (my_gate + 3) % 4;  // Subtract one from my_gate
  103.  
  104.       cout <<
  105.          "A message is heard on the airport paging system, \"All"
  106.          " gates\nhave been rescheduled due to bad weather.  No "
  107.          "flights have\nbeen cancelled at this time.\"\n";
  108.  
  109.    }
  110. }
  111.  
  112.  
  113.  
  114.  
  115.                                 // This freezes the gate assignments
  116. void
  117. schedule::list_flights(location *current_location)
  118. {
  119.    if (current_location == &waiting_area)
  120.       gates_frozen = TRUE;
  121.  
  122.    for (int index = 0 ; index < 4 ; index++) {
  123.       printf("Gate %d - Flight %3d - %s - ",
  124.               (index + 1),
  125.               flight_number[index],
  126.               destination[index]);
  127.       list_time(index);
  128.    }
  129. }
  130.  
  131.  
  132.  
  133.  
  134. void
  135. schedule::gate_message(location *current_location)
  136. {
  137. int index;
  138.  
  139.               // Find gate we are at and print message
  140.    for (index = 0;index < 4;index++)
  141.       if (current_location == gate[index]) goto gate_is_found;
  142.  
  143.    return;    // If not a gate
  144.  
  145.    gate_is_found:
  146.    printf("Flight %3d - %s - ",     // If a gate is found
  147.            flight_number[index],
  148.            destination[index]);
  149.    list_time(index);
  150. }
  151.  
  152.  
  153.  
  154.  
  155.                                    // This freezes the players flight
  156. void
  157. schedule::list_actual_destination(void)
  158. {
  159.       flights_frozen = TRUE;
  160.  
  161.       printf("Flight %3d - %s - ",
  162.            flight_number[my_gate],
  163.            destination[my_gate]);
  164.       list_time(my_gate);
  165. }
  166.  
  167.  
  168.  
  169.  
  170. void
  171. schedule::list_time(int index)
  172. {
  173.    if (depart_minute[index] < 10)
  174.       printf("%d:0%d\n",depart_hour[index], depart_minute[index]);
  175.    else
  176.       printf("%d:%d\n",depart_hour[index], depart_minute[index]);
  177. }
  178.  
  179.  
  180.  
  181.  
  182. void
  183. schedule::check_flight(location *current_location)
  184. {
  185.  
  186.    if ((current_location == &plane1) ||
  187.          (current_location == &plane2) ||
  188.            (current_location == &plane3) ||
  189.              (current_location == &plane4)) {
  190.  
  191.                                             // You must have a ticket
  192.       if (!personal_items.item_here(ticket))
  193.          cout << 
  194.          "Unfortunately, you don't have a ticket, you are arrested\n"
  195.          "as a stowaway and drug off the plane screaming.  No vaca-\n"
  196.          "tion for you.\n";
  197.  
  198.                                             // On plane 1 from gate 1
  199.       else if ((current_location == &plane1) && (my_gate != 0))
  200.          cout <<
  201.          "Unfortunately, you are at gate 1 and this flight is going\n"
  202.          " to " << destination[0] << ".  Better luck next time.\n";
  203.  
  204.                                             // On plane 2 from gate 2
  205.       else if ((current_location == &plane2) && (my_gate != 1))
  206.          cout <<
  207.          "Unfortunately, you are at gate 2 and this flight is going\n"
  208.          " to " << destination[1] << ".  Better luck next time.\n";
  209.  
  210.                                             // On plane 3 from gate 3
  211.       else if ((current_location == &plane3) && (my_gate != 2))
  212.          cout <<
  213.          "Unfortunately, you are at gate 3 and this flight is going\n"
  214.          " to " << destination[2] << ".  Better luck next time.\n";
  215.  
  216.                                             // On plane 4 from gate 4
  217.       else if ((current_location == &plane4) && (my_gate != 3))
  218.          cout <<
  219.          "Unfortunately, you are at gate 4 and this flight is going\n"
  220.          " to " << destination[3] << ".  Better luck next time.\n";
  221.  
  222.                                                // You must be on time
  223.       else if ((time_of_day.present_hour() > depart_hour[my_gate]) ||
  224.                (time_of_day.present_minute() > depart_minute[my_gate]))
  225.          cout <<
  226.          "Unfortunately, you are too late for your flight and are\n"
  227.          "aboard a cargo plane to Greasy Creek, Missouri.  Better\n"
  228.          "luck next time.\n";
  229.  
  230.                                                // You must have candy
  231.       else if (!personal_items.item_here(candy))
  232.          cout <<
  233.          "Unfortunately, you failed to bring any food along and you\n"
  234.          "died of malnutrition half way to your destination.\n";
  235.  
  236.                                       // You must visit the rest room
  237.       else if (!visited_rest_room)
  238.          cout <<
  239.          "Unfortunately, you forgot to take care of your bladder\n"
  240.          "problem back at the airport.  The restrooms on this plane\n"
  241.          "are out-of-order.  You suffer a ruptured bladder and die\n"
  242.          "enroute to your destination.\n";
  243.  
  244.                              // A successful trip through the airport
  245.       else 
  246.          cout <<
  247.          "Congratulations, you are comfortably enroute to your well\n"
  248.          "deserved vacation.  You can study the source code to this\n"
  249.          "program on the plane.  If you do not have the source code,\n"
  250.          "you can read the paper in the lobby for the address where\n"
  251.          "you can write for more information.\n";
  252.  
  253.       cout  << "\nHit any key to end the game.\n";
  254.       getch();           // Wait for keyhit
  255.       verb = quit;       // verb is global, end the game
  256.    }
  257. }
  258.  
  259.